package com.jmxcfc.blfsc.huisheng.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jmxcfc.blfsc.huisheng.entity.vo.NotifyResponseVo;
import com.jmxcfc.blfsc.huisheng.service.IVoiceNotifyRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 慧声语音:语音回调控制器
 * </p>
 * @author pbs
 */
@RestController
@RequestMapping("/huisheng")
@Slf4j
public class HuiShengNotifyController {

    private IVoiceNotifyRecordService voiceNotifyRecordService;

    @Autowired
    public void setVoiceNotifyRecordService(IVoiceNotifyRecordService voiceNotifyRecordService) {
        this.voiceNotifyRecordService = voiceNotifyRecordService;
    }

    /**
     * 主动推送数据
     * @param notifyData
     * @return
     */
    @RequestMapping("/voice/notify")
    public JSONObject voiceNotify(@RequestBody String notifyData) {
        try {
            log.info("慧声语音-数据推送回调通知,通知数据:{}", notifyData);
            JSONObject response =  JSON.parseObject(JSON.toJSONString(voiceNotifyRecordService.voiceNotifyHandler(notifyData)));
            log.info("慧声语音-数据推送回调通知,处理结束,同步响应结果:{}", response);
            return response;
        } catch (Exception e) {
            log.info("慧声语音-数据推送回调,回调通知处理异常,异常信息:{}", e.getMessage(), e);
            return JSON.parseObject(JSON.toJSONString(NotifyResponseVo.fail("接收失败")));
        }
    }

}
